# Maintainer: Patrick Stewart <patstew@gmail.com>

_realname=ipykernel
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=4.6.1
pkgrel=1
pkgdesc="The ipython kernel for Jupyter (mingw-w64)"
arch=('any')
url="https://ipython.org/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/ipython/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('b52022f5a1bd026862ec49195f7ce2c915fbd9772c9e04ce4e778dba159d92a6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

all_build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/${1} setup.py install \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  find "${pkgdir}/" -name "*.pyc" -delete
  find "${pkgdir}/" -type d -empty -delete

  # setuptools doesnt see mingw-w64-python's readline
  find "${pkgdir}/" -name 'requires.txt' -delete
}

package_python3-ipykernel() {
  local interpreter=python3
  #install=ipython3-${CARCH}.install
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-pathlib2"
           "${MINGW_PACKAGE_PREFIX}-python3-pyzmq"
           "${MINGW_PACKAGE_PREFIX}-python3-ipython")

  all_build ${interpreter}
}

package_python2-ipykernel() {
  local interpreter=python2
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-backports.shutil_get_terminal_size"
           "${MINGW_PACKAGE_PREFIX}-python2-pathlib2"
           "${MINGW_PACKAGE_PREFIX}-python2-pyzmq"
           "${MINGW_PACKAGE_PREFIX}-python2-ipython")

  all_build ${interpreter}
}

package_mingw-w64-i686-python2-ipykernel() {
  package_python2-ipykernel
}

package_mingw-w64-i686-python3-ipykernel() {
  package_python3-ipykernel
}

package_mingw-w64-x86_64-python2-ipykernel() {
  package_python2-ipykernel
}

package_mingw-w64-x86_64-python3-ipykernel() {
  package_python3-ipykernel
}
